Technical Q&A QA1196
AudioDevice sample rates




ÉTÉìÉvÉäÉìÉOë¨ìxÇÃéÊìæÇΔê›íË

QÅFAudioDevice ÇÃÉTÉìÉvÉäÉìÉOë¨ìxÇÃéÊìæÇΔê›íËÇçsǧDžÇÕǫǧÇ∑ÇÍÇŒÇÊÇ¢Ç≈ǵÇÂǧÅB

AÅFâ∫ãLÇÃÉRÅ[ÉhÇÕ CoreAudio SDKÅi/Developer/Examples/CoreAudio/PublicUtility/CAAudioHardwareDevice.*ÅjÇ©ÇÁÇÃî≤êàÇ≈Ç∑ÅBDZÇÍÇégǡǃÅAéwíËÇ≥ÇÍÇΩ AudioDevice Ç≈óòópâ¬î\Ç»ÉTÉìÉvÉäÉìÉOë¨ìxÇÃéÊìæÇΔê›íËÇçsǧDZÇΔÇ™Ç≈Ç´Ç‹Ç∑ÅB



ÉäÉXÉg 1Å@ÉTÉìÉvÉäÉìÉOë¨ìxÇÃîÕàÕÇéÊìæÇ®ÇÊÇ—ê›íËÇ∑ÇÈï˚ñ@

Float64 CAAudioHardwareDevice::GetNominalSampleRate() const
{
    Float64 theAnswer = 0;
    UInt32 theSize = sizeof(Float64);
    GetPropertyData(0, 
                               kAudioDeviceSectionGlobal, 
                               kAudioDevicePropertyNominalSampleRate, 
                               theSize, 
                               &theAnswer);
    return theAnswer;
}

void CAAudioHardwareDevice::SetNominalSampleRate(Float64 inSampleRate)
{
    UInt32 theSize = sizeof(Float64);
    SetPropertyData(0, 
                              kAudioDeviceSectionGlobal, 
                              kAudioDevicePropertyNominalSampleRate, 
                              theSize, 
                              &inSampleRate);
}

UInt32 CAAudioHardwareDevice::GetNumberNominalSampleRateRanges() const
{
    UInt32 theSize = GetPropertyDataSize(0, 
                        kAudioDeviceSectionGlobal,
                        kAudioDevicePropertyAvailableNominalSampleRates);
       
    return (theSize / sizeof(AudioValueRange) );
}

void    GetNominalSampleRateRanges(UInt32& ioNumberRanges,
                                   AudioValueRange* outRanges) const
{
    UInt32 theSize = ioNumberRanges * sizeof(AudioValueRange);
    GetPropertyData(0, 
                   kAudioDeviceSectionGlobal,
                   kAudioDevicePropertyAvailableNominalSampleRates, 
                   theSize,
                   outRanges);

    ioNumberRanges = theSize / sizeof(AudioValueRange);
}

UInt32 CAAudioHardwareDevice::GetPropertyDataSize(UInt32 inChannel,
                 CAAudioHardwareDeviceSectionID inSection, 
                 AudioHardwarePropertyID inPropertyID) const
{
    UInt32 theSize = 0;
    OSStatus theError;
    theError = AudioDeviceGetPropertyInfo(mAudioDeviceID, 
                                 inChannel, 
                                 inSection, 
                                 inPropertyID, 
                                 &theSize,
                                  NULL);
      ThrowIfError(theError,
                    CAException(theError), 
                    "error getting info about a property");
    return theSize;
}

void    CAAudioHardwareDevice::GetPropertyData(UInt32 inChannel,
                                  CAAudioHardwareDeviceSectionID inSection,
                                  AudioHardwarePropertyID inPropertyID,
                                  UInt32& ioDataSize, 
                                  void* outData) const
{
    OSStatus theError;
    theError = AudioDeviceGetProperty(mAudioDeviceID, 
                                 inChannel, 
                                 inSection, 
                                 inPropertyID, 
                                 &ioDataSize, 
                                 outData);
     ThrowIfError(theError,
                  CAException(theError), 
                  "error getting the value of a property");
}

void    CAAudioHardwareDevice::SetPropertyData(UInt32 inChannel,    
                                 CAAudioHardwareDeviceSectionID inSection, 
                                 AudioHardwarePropertyID inPropertyID, 
                                 UInt32 inDataSize, 
                                 const void* inData, 
                                 const AudioTimeStamp* inWhen)
{
    OSStatus theError;
    theError = AudioDeviceSetProperty(mAudioDeviceID,
                                               inWhen,
                                               inChannel, 
                                               inSection, 
                                               inPropertyID,
                                               inDataSize, 
                                               inData);
       ThrowIfError(theError, 
                     CAException(theError),
                     "error setting the value of a property");
}





êÊì™Ç…ñflÇÈ



ÉTÉìÉvÉäÉìÉOë¨ìxÇÃïœä∑

QÅFì¸óÕÉIÅ[ÉfÉBÉIÉfÉoÉCÉXÇΔèoóÕÉIÅ[ÉfÉBÉIÉfÉoÉCÉXÇÃÉTÉìÉvÉäÉìÉOë¨ìxÇ™àŸÇ»Ç¡ÇƒÇ¢Ç‹Ç∑ÅB2 ǬÇÃÉfÉoÉCÉXÇÃä‘Ç≈ïœä∑ÇçsǧDžÇÕǫǧÇ∑ÇÍÇŒÇÊÇ¢Ç≈ǵÇÂǧǩÅB

AÅFǪÇÃÇΩÇflÇÃï˚ñ@ÇÕ 2 ǬdžÇËÇ‹Ç∑ÅB

Åi1ÅjAudioConverter ÇégǡǃÉfÉoÉCÉXä‘ÇÃÉTÉìÉvÉäÉìÉOë¨ìxÇÃïœä∑ÇçsǧDZÇΔÇ™Ç≈Ç´Ç‹Ç∑ÅBì¸óÕÇΔèoóÕÇÃÉXÉgÉäÅ[ÉÄÉtÉHÅ[É}ÉbÉgÇéwíËǵǃÅAAudioConverter ÇçÏê¨Ç≈Ç´Ç‹Ç∑ÅBéüÇ…ÅAAudioConverterFillBuffer ÇégǡǃÉfÅ[É^ÇÃÉoÉbÉtÉ@Çïœä∑Ç∑ÇÈïKóvǙdžÇËÇ‹Ç∑ÅB

Åi2ÅjDefaultOutputUnit ÇégópǵNjÇ∑ÅBDZÇÍÇÕì¸óÕÉfÉoÉCÉXÇΔè»ó™éûÇÃèoóÕÉfÉoÉCÉXÇΔÇÃä‘ÇÃÉTÉìÉvÉäÉìÉOë¨ìxÇÃïœä∑Çé©ìÆìIÇ…çsǢNjÇ∑ÅBè⁄ç◊DžǬǢǃÇÕÅAÉTÉìÉvÉãÉRÅ[Éh DefaultOutputUnitÅi/Developer/Examples/CoreAudio/Services/DefaultOutputUnitÅjÇéQèΔǵǃÇ≠ÇæÇ≥Ç¢ÅB


[2003 îN 12 åé 5 ì˙]